<?php


function load_valid_moves($board)
{
	for($i=0;$i<strlen($board);$i++)
	{
		switch($board[$i])
		{
			case 'k': valid_black_king_moves($board,$i); break;
			case 'q': valid_black_queen_moves($board,$i); break;
			case 'b': valid_black_bishop_moves($board,$i); break;
			case 'n': valid_black_knight_moves($board,$i); break;
			case 'r': valid_black_rook_moves($board,$i); break;
			case 'p': valid_black_pawn_moves($board,$i); break;
			case 'K': valid_white_king_moves($board,$i); break;
			case 'Q': valid_white_queen_moves($board,$i); break;
			case 'B': valid_white_bishop_moves($board,$i); break;
			case 'N': valid_white_knight_moves($board,$i); break;
			case 'R': valid_white_rook_moves($board,$i); break;
			case 'P': valid_white_pawn_moves($board,$i); break;
		}
	}
}


function valid_white_king_moves($board,$pos)
{
	global $valid_white_moves;
	
	// check north
	$n = whats_north($board,$pos);
	if(DEBUG) print("n: $n<br>\n");
	if($n && ($n=='.' || ord($n) > 96))
		$valid_white_moves[] = move_north($board,$pos);
	
	// check west
	$w = whats_west($board,$pos);
	if(DEBUG) print("w: $w<br>\n");
	if($w && ($w=='.' || ord($w) > 96))
		$valid_white_moves[] = move_west($board,$pos);

	// check south
	$s = whats_south($board,$pos);
	if(DEBUG) print("s: $s<br>\n");
	if($s && ($s=='.' || ord($s) > 96))
		$valid_white_moves[] = move_south($board,$pos);

	// check east
	$e = whats_east($board,$pos);
	if(DEBUG) print("e: $e<br>\n");
	if($e && ($e=='.' || ord($e) > 96))
		$valid_white_moves[] = move_east($board,$pos);
	
	// check southeast
	$se = whats_southeast($board,$pos);
	if(DEBUG) print("se: $se<br>\n");
	if($se && ($se=='.' || ord($se) > 96))
		$valid_white_moves[] = move_southeast($board,$pos);
	
	// check southwest
	$sw = whats_southwest($board,$pos);
	if(DEBUG) print("sw: $sw<br>\n");
	if($sw && ($sw=='.' || ord($sw) > 96))
		$valid_white_moves[] = move_southwest($board,$pos);
	
	// check northwest
	$nw = whats_northwest($board,$pos);
	if(DEBUG) print("nw: $nw<br>\n");
	if($nw && ($nw=='.' || ord($nw) > 96))
		$valid_white_moves[] = move_northwest($board,$pos);
	
	// check northeast
	$ne = whats_northeast($board,$pos);
	if(DEBUG) print("ne: $ne<br>\n");
	if($ne && ($ne=='.' || ord($ne) > 96))
		$valid_white_moves[] = move_northeast($board,$pos);
}

function valid_white_queen_moves($board,$pos)
{
	global $valid_white_moves;
	
	$orig_board = $board;
	$orig_pos = $pos;
	
	// check north
	while(true)
	{
		$n = whats_north($board,$pos);
		if(DEBUG) print("n: $n<br>\n");
		if($n && ($n=='.' || ord($n) > 96))
		{
			$board = move_north($board,$pos);
			$valid_white_moves[] = $board;
			if($n!='.') break;
		}
		else
			break;
		$pos -= 5;
	}
	
	// check west
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$w = whats_west($board,$pos);
		if(DEBUG) print("w: $w<br>\n");
		if($w && ($w=='.' || ord($w) > 96))
		{
			$board = move_west($board,$pos);
			$valid_white_moves[] = $board;
			if($w!='.') break;
		}
		else
			break;
		$pos--;
	}
	
	
	// check south
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$s = whats_south($board,$pos);
		if(DEBUG) print("s: $s<br>\n");
		if($s && ($s=='.' || ord($s) > 96))
		{
			$board = move_south($board,$pos);
			$valid_white_moves[] = $board;
			if($s!='.') break;
		}
		else
			break;
		$pos += 5;
	}
	
	
	// check east
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$e = whats_east($board,$pos);
		if(DEBUG) print("e: $e<br>\n");
		if($e && ($e=='.' || ord($e) > 96))
		{
			$board = move_east($board,$pos);
			$valid_white_moves[] = $board;
			if($e!='.') break;
		}
		else
			break;
		$pos++;
	}
	
	
	// check southeast
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$se = whats_southeast($board,$pos);
		if(DEBUG) print("se: $se<br>\n");
		if($se && ($se=='.' || ord($se) > 96))
		{
			$board = move_southeast($board,$pos);
			$valid_white_moves[] = $board;
			if($se!='.') break;
		}
		else
			break;
		$pos += 6;
	}
	
	
	
	// check southwest
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$sw = whats_southwest($board,$pos);
		if(DEBUG) print("sw: $sw<br>\n");
		if($sw && ($sw=='.' || ord($sw) > 96))
		{
			$board = move_southwest($board,$pos);
			$valid_white_moves[] = $board;
			if($sw!='.') break;
		}
		else
			break;
		$pos += 4;
	}
	
	
	// check northwest
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$nw = whats_northwest($board,$pos);
		if(DEBUG) print("nw: $nw<br>\n");
		if($nw && ($nw=='.' || ord($nw) > 96))
		{
			$board = move_northwest($board,$pos);
			$valid_white_moves[] = $board;
			if($nw!='.') break;
		}
		else
			break;
		$pos -= 6;	
	}
	
	
	// check northeast
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$ne = whats_northeast($board,$pos);
		if(DEBUG) print("ne: $ne<br>\n");
		if($ne && ($ne=='.' || ord($ne) > 96))
		{
			$board = move_northeast($board,$pos);
			$valid_white_moves[] = $board;
			if($ne!='.') break;
		}
		else
			break;
		$pos -= 4;
	}
}

function valid_white_rook_moves($board,$pos)
{
	global $valid_white_moves;
	
	$orig_board = $board;
	$orig_pos = $pos;
	
	// check north
	while(true)
	{
		$n = whats_north($board,$pos);
		if(DEBUG) print("n: $n<br>\n");
		if($n && ($n=='.' || ord($n) > 96))
		{
			$board = move_north($board,$pos);
			$valid_white_moves[] = $board;
			if($n!='.') break;
		}
		else
			break;
		$pos -= 5;
	}
	
	// check west
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$w = whats_west($board,$pos);
		if(DEBUG) print("w: $w<br>\n");
		if($w && ($w=='.' || ord($w) > 96))
		{
			$board = move_west($board,$pos);
			$valid_white_moves[] = $board;
			if($w!='.') break;
		}
		else
			break;
		$pos--;
	}
	
	// check south
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$s = whats_south($board,$pos);
		if(DEBUG) print("s: $s<br>\n");
		if($s && ($s=='.' || ord($s) > 96))
		{
			$board = move_south($board,$pos);
			$valid_white_moves[] = $board;
			if($s!='.') break;
		}
		else
			break;
		$pos += 5;
	}
	
	// check east
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$e = whats_east($board,$pos);
		if(DEBUG) print("e: $e<br>\n");
		if($e && ($e=='.' || ord($e) > 96))
		{
			$board = move_east($board,$pos);
			$valid_white_moves[] = $board;
			if($e!='.') break;
		}
		else
			break;
		$pos++;
	}
}

function valid_white_bishop_moves($board,$pos)
{
	global $valid_white_moves;
	
	$orig_board = $board;
	$orig_pos = $pos;
	
	// check north
	$n = whats_north($board,$pos);
	if(DEBUG) print("n: $n<br>\n");
	if($n && $n=='.')
		$valid_white_moves[] = move_north($board,$pos);
	
	// check west
	$w = whats_west($board,$pos);
	if(DEBUG) print("w: $w<br>\n");
	if($w && $w=='.')
		$valid_white_moves[] = move_west($board,$pos);

	// check south
	$s = whats_south($board,$pos);
	if(DEBUG) print("s: $s<br>\n");
	if($s && $s=='.')
		$valid_white_moves[] = move_south($board,$pos);

	// check east
	$e = whats_east($board,$pos);
	if(DEBUG) print("e: $e<br>\n");
	if($e && $e=='.')
		$valid_white_moves[] = move_east($board,$pos);
	
	// check southeast
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$se = whats_southeast($board,$pos);
		if(DEBUG) print("se: $se<br>\n");
		if($se && ($se=='.' || ord($se) > 96))
		{
			$board = move_southeast($board,$pos);
			$valid_white_moves[] = $board;
			if($se!='.') break;
		}
		else
			break;
		$pos += 6;
	}
	
	
	
	// check southwest
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$sw = whats_southwest($board,$pos);
		if(DEBUG) print("sw: $sw<br>\n");
		if($sw && ($sw=='.' || ord($sw) > 96))
		{
			$board = move_southwest($board,$pos);
			$valid_white_moves[] = $board;
			if($sw!='.') break;
		}
		else
			break;
		$pos += 4;
	}
	
	
	// check northwest
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$nw = whats_northwest($board,$pos);
		if(DEBUG) print("nw: $nw<br>\n");
		if($nw && ($nw=='.' || ord($nw) > 96))
		{
			$board = move_northwest($board,$pos);
			$valid_white_moves[] = $board;
			if($nw!='.') break;
		}
		else
			break;
		$pos -= 6;	
	}
	
	
	// check northeast
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$ne = whats_northeast($board,$pos);
		if(DEBUG) print("ne: $ne<br>\n");
		if($ne && ($ne=='.' || ord($ne) > 96))
		{
			$board = move_northeast($board,$pos);
			$valid_white_moves[] = $board;
			if($ne!='.') break;
		}
		else
			break;
		$pos -= 4;
	}
}

function valid_white_knight_moves($board,$pos)
{
	global $valid_white_moves;
	
	// check northwest
	$nw = whats_knight_northwest($board,$pos);
	if(DEBUG) print("nw: $nw<br>\n");
	if($nw && ($nw=='.' || ord($nw) > 96))
		$valid_white_moves[] = move_knight_northwest($board,$pos);
	
	// check northeast
	$ne = whats_knight_northeast($board,$pos);
	if(DEBUG) print("ne: $ne<br>\n");
	if($ne && ($ne=='.' || ord($ne) > 96))
		$valid_white_moves[] = move_knight_northeast($board,$pos);
		
	// check eastnorth
	$en = whats_knight_eastnorth($board,$pos);
	if(DEBUG) print("en: $en<br>\n");
	if($en && ($en=='.' || ord($en) > 96))
		$valid_white_moves[] = move_knight_eastnorth($board,$pos);
		
	// check eastsouth
	$es = whats_knight_eastsouth($board,$pos);
	if(DEBUG) print("es: $es<br>\n");
	if($es && ($es=='.' || ord($es) > 96))
		$valid_white_moves[] = move_knight_eastsouth($board,$pos);
		
	// check southeast
	$se = whats_knight_southeast($board,$pos);
	if(DEBUG) print("se: $se<br>\n");
	if($se && ($se=='.' || ord($se) > 96))
		$valid_white_moves[] = move_knight_southeast($board,$pos);
		
	// check southwest
	$sw = whats_knight_southwest($board,$pos);
	if(DEBUG) print("sw: $sw<br>\n");
	if($sw && ($sw=='.' || ord($sw) > 96))
		$valid_white_moves[] = move_knight_southwest($board,$pos);
		
	// check westsouth
	$ws = whats_knight_westsouth($board,$pos);
	if(DEBUG) print("ws: $ws<br>\n");
	if($ws && ($ws=='.' || ord($ws) > 96))
		$valid_white_moves[] = move_knight_westsouth($board,$pos);
		
	// check westnorth
	$wn = whats_knight_westnorth($board,$pos);
	if(DEBUG) print("wn: $wn<br>\n");
	if($wn && ($wn=='.' || ord($wn) > 96))
		$valid_white_moves[] = move_knight_westnorth($board,$pos);		
}

function valid_white_pawn_moves($board,$pos)
{
	global $valid_white_moves;
	
	// check north
	$n = whats_north($board,$pos);
	if(DEBUG) print("n: $n<br>\n");
	if($n && $n=='.')
		$valid_white_moves[] = move_pawn_north($board,$pos);
	
	// check northwest
	$nw = whats_northwest($board,$pos);
	if(DEBUG) print("nw: $nw<br>\n");
	if($nw && ord($nw) > 96)
		$valid_white_moves[] = move_pawn_northwest($board,$pos);
	
	// check northeast
	$ne = whats_northeast($board,$pos);
	if(DEBUG) print("ne: $ne<br>\n");
	if($ne && ord($ne) > 96)
		$valid_white_moves[] = move_pawn_northeast($board,$pos);
}




function valid_black_king_moves($board,$pos)
{
	global $valid_black_moves;
	
	// check north
	$n = whats_north($board,$pos);
	if(DEBUG) print("n: $n<br>\n");
	if($n && ord($n) < 96)
		$valid_black_moves[] = move_north($board,$pos);
	
	// check west
	$w = whats_west($board,$pos);
	if(DEBUG) print("w: $w<br>\n");
	if($w && ord($w) < 96)
		$valid_black_moves[] = move_west($board,$pos);

	// check south
	$s = whats_south($board,$pos);
	if(DEBUG) print("s: $s<br>\n");
	if($s && ord($s) < 96)
		$valid_black_moves[] = move_south($board,$pos);

	// check east
	$e = whats_east($board,$pos);
	if(DEBUG) print("e: $e<br>\n");
	if($e && ord($e) < 96)
		$valid_black_moves[] = move_east($board,$pos);
	
	// check southeast
	$se = whats_southeast($board,$pos);
	if(DEBUG) print("se: $se<br>\n");
	if($se && ord($se) < 96)
		$valid_black_moves[] = move_southeast($board,$pos);
	
	// check southwest
	$sw = whats_southwest($board,$pos);
	if(DEBUG) print("sw: $sw<br>\n");
	if($sw && ord($sw) < 96)
		$valid_black_moves[] = move_southwest($board,$pos);
	
	// check northwest
	$nw = whats_northwest($board,$pos);
	if(DEBUG) print("nw: $nw<br>\n");
	if($nw && ord($nw) < 96)
		$valid_black_moves[] = move_northwest($board,$pos);
	
	// check northeast
	$ne = whats_northeast($board,$pos);
	if(DEBUG) print("ne: $ne<br>\n");
	if($ne && ord($ne) < 96)
		$valid_black_moves[] = move_northeast($board,$pos);
}

function valid_black_queen_moves($board,$pos)
{
	global $valid_black_moves;
	
	$orig_board = $board;
	$orig_pos = $pos;
	
	// check north
	while(true)
	{
		$n = whats_north($board,$pos);
		if(DEBUG) print("n: $n<br>\n");
		if($n && ord($n) < 96)
		{
			$board = move_north($board,$pos);
			$valid_black_moves[] = $board;
			if($n!='.') break;
		}
		else
			break;
		$pos -= 5;
	}
	
	// check west
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$w = whats_west($board,$pos);
		if(DEBUG) print("w: $w<br>\n");
		if($w && ord($w) < 96)
		{
			$board = move_west($board,$pos);
			$valid_black_moves[] = $board;
			if($w!='.') break;
		}
		else
			break;
		$pos--;
	}
	
	// check south
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$s = whats_south($board,$pos);
		if(DEBUG) print("s: $s<br>\n");
		if($s && ord($s) < 96)
		{
			$board = move_south($board,$pos);
			$valid_black_moves[] = $board;
			if($s!='.') break;
		}
		else
			break;
		$pos += 5;
	}
	
	
	// check east
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$e = whats_east($board,$pos);
		if(DEBUG) print("e: $e<br>\n");
		if($e && ord($e) < 96)
		{
			$board = move_east($board,$pos);
			$valid_black_moves[] = $board;
			if($e!='.') break;
		}
		else
			break;
		$pos++;
	}
	
	// check southeast
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$se = whats_southeast($board,$pos);
		if(DEBUG) print("se: $se<br>\n");
		if($se && ord($se) < 96)
		{
			$board = move_southeast($board,$pos);
			$valid_black_moves[] = $board;
			if($se!='.') break;
		}
		else
			break;
		$pos += 6;
	}
	
	// check southwest
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$sw = whats_southwest($board,$pos);
		if(DEBUG) print("sw: $sw<br>\n");
		if($sw && ord($sw) < 96)
		{
			$board = move_southwest($board,$pos);
			$valid_black_moves[] = $board;
			if($sw!='.') break;
		}
		else
			break;
		$pos += 4;
	}
	
	
	// check northwest
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$nw = whats_northwest($board,$pos);
		if(DEBUG) print("nw: $nw<br>\n");
		if($nw && ord($nw) < 96)
		{
			$board = move_northwest($board,$pos);
			$valid_black_moves[] = $board;
			if($nw!='.') break;
		}
		else
			break;
		$pos -= 6;	
	}
	
	// check northeast
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$ne = whats_northeast($board,$pos);
		if(DEBUG) print("ne: $ne<br>\n");
		if($ne && ord($ne) < 96)
		{
			$board = move_northeast($board,$pos);
			$valid_black_moves[] = $board;
			if($ne!='.') break;
		}
		else
			break;
		$pos -= 4;
	}
}

function valid_black_rook_moves($board,$pos)
{
	global $valid_black_moves;
	
	$orig_board = $board;
	$orig_pos = $pos;
	
	// check north
	while(true)
	{
		$n = whats_north($board,$pos);
		if(DEBUG) print("n: $n<br>\n");
		if($n && ord($n) < 96)
		{
			$board = move_north($board,$pos);
			$valid_black_moves[] = $board;
			if($n!='.') break;
		}
		else
			break;
		$pos -= 5;
	}
	
	// check west
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$w = whats_west($board,$pos);
		if(DEBUG) print("w: $w<br>\n");
		if($w && ord($w) < 96)
		{
			$board = move_west($board,$pos);
			$valid_black_moves[] = $board;
			if($w!='.') break;
		}
		else
			break;
		$pos--;
	}
	
	// check south
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$s = whats_south($board,$pos);
		if(DEBUG) print("s: $s<br>\n");
		if($s && ord($s) < 96)
		{
			$board = move_south($board,$pos);
			$valid_black_moves[] = $board;
			if($s!='.') break;
		}
		else
			break;
		$pos += 5;
	}
	
	// check east
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$e = whats_east($board,$pos);
		if(DEBUG) print("e: $e<br>\n");
		if($e && ord($e) < 96)
		{
			$board = move_east($board,$pos);
			$valid_black_moves[] = $board;
			if($e!='.') break;
		}
		else
			break;
		$pos++;
	}
}

function valid_black_bishop_moves($board,$pos)
{
	global $valid_black_moves;
	
	$orig_board = $board;
	$orig_pos = $pos;
	
	// check north
	$n = whats_north($board,$pos);
	if(DEBUG) print("n: $n<br>\n");
	if($n && $n=='.')
		$valid_black_moves[] = move_north($board,$pos);
	
	// check west
	$w = whats_west($board,$pos);
	if(DEBUG) print("w: $w<br>\n");
	if($w && $w=='.')
		$valid_black_moves[] = move_west($board,$pos);

	// check south
	$s = whats_south($board,$pos);
	if(DEBUG) print("s: $s<br>\n");
	if($s && $s=='.')
		$valid_black_moves[] = move_south($board,$pos);

	// check east
	$e = whats_east($board,$pos);
	if(DEBUG) print("e: $e<br>\n");
	if($e && $e=='.')
		$valid_black_moves[] = move_east($board,$pos);
	
	// check southeast
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$se = whats_southeast($board,$pos);
		if(DEBUG) print("se: $se<br>\n");
		if($se && ord($se) < 96)
		{
			$board = move_southeast($board,$pos);
			$valid_black_moves[] = $board;
			if($se!='.') break;
		}
		else
			break;
		$pos += 6;
	}
	
	// check southwest
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$sw = whats_southwest($board,$pos);
		if(DEBUG) print("sw: $sw<br>\n");
		if($sw && ord($sw) < 96)
		{
			$board = move_southwest($board,$pos);
			$valid_black_moves[] = $board;
			if($sw!='.') break;
		}
		else
			break;
		$pos += 4;
	}
	
	// check northwest
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$nw = whats_northwest($board,$pos);
		if(DEBUG) print("nw: $nw<br>\n");
		if($nw && ord($nw) < 96)
		{
			$board = move_northwest($board,$pos);
			$valid_black_moves[] = $board;
			if($nw!='.') break;
		}
		else
			break;
		$pos -= 6;	
	}
	
	// check northeast
	$board = $orig_board;
	$pos = $orig_pos;
	while(true)
	{
		$ne = whats_northeast($board,$pos);
		if(DEBUG) print("ne: $ne<br>\n");
		if($ne && ord($ne) < 96)
		{
			$board = move_northeast($board,$pos);
			$valid_black_moves[] = $board;
			if($ne!='.') break;
		}
		else
			break;
		$pos -= 4;
	}
}

function valid_black_knight_moves($board,$pos)
{
	global $valid_black_moves;
	
	// check northwest
	$nw = whats_knight_northwest($board,$pos);
	if(DEBUG) print("nw: $nw<br>\n");
	if($nw && ord($nw) < 96)
		$valid_black_moves[] = move_knight_northwest($board,$pos);
	
	// check northeast
	$ne = whats_knight_northeast($board,$pos);
	if(DEBUG) print("ne: $ne<br>\n");
	if($ne && ord($ne) < 96)
		$valid_black_moves[] = move_knight_northeast($board,$pos);
		
	// check eastnorth
	$en = whats_knight_eastnorth($board,$pos);
	if(DEBUG) print("en: $en<br>\n");
	if($en && ord($en) < 96)
		$valid_black_moves[] = move_knight_eastnorth($board,$pos);
		
	// check eastsouth
	$es = whats_knight_eastsouth($board,$pos);
	if(DEBUG) print("es: $es<br>\n");
	if($es && ord($es) < 96)
		$valid_black_moves[] = move_knight_eastsouth($board,$pos);
		
	// check southeast
	$se = whats_knight_southeast($board,$pos);
	if(DEBUG) print("se: $se<br>\n");
	if($se && ord($se) < 96)
		$valid_black_moves[] = move_knight_southeast($board,$pos);
		
	// check southwest
	$sw = whats_knight_southwest($board,$pos);
	if(DEBUG) print("sw: $sw<br>\n");
	if($sw && ord($sw) < 96)
		$valid_black_moves[] = move_knight_southwest($board,$pos);
		
	// check westsouth
	$ws = whats_knight_westsouth($board,$pos);
	if(DEBUG) print("ws: $ws<br>\n");
	if($ws && ord($ws) < 96)
		$valid_black_moves[] = move_knight_westsouth($board,$pos);
		
	// check westnorth
	$wn = whats_knight_westnorth($board,$pos);
	if(DEBUG) print("wn: $wn<br>\n");
	if($wn && ord($wn) < 96)
		$valid_black_moves[] = move_knight_westnorth($board,$pos);		
}

function valid_black_pawn_moves($board,$pos)
{
	global $valid_black_moves;
	
	// check south
	$s = whats_south($board,$pos);
	if(DEBUG) print("s: $s<br>\n");
	if($s && $s=='.')
		$valid_black_moves[] = move_pawn_south($board,$pos);
	
	// check southwest
	$sw = whats_southwest($board,$pos);
	if(DEBUG) print("sw: $sw<br>\n");
	if($sw && $sw!='.' && ord($sw) < 96)
		$valid_black_moves[] = move_pawn_southwest($board,$pos);
	
	// check southeast
	$se = whats_southeast($board,$pos);
	if(DEBUG) print("se: $se<br>\n");
	if($se && $se!='.' && ord($se) > 96)
		$valid_black_moves[] = move_pawn_southeast($board,$pos);
}



?>